/**
 * Created by IntelliJ IDEA.
 * User: Bezdelnick
 * Date: 9/26/12
 * Time: 8:26 PM
 * To change this template use File | Settings | File Templates.
 */
package vplib.component.body {
import alternativa.engine3d.objects.Mesh;

import vplib.component.*;

import alternativa.engine3d.core.Object3D;

import alternativa.engine3d.materials.FillMaterial;
import alternativa.engine3d.primitives.Box;

import vplib.dictionary.PropertiesDictionary;
import vplib.model.AbstractPropertyModel;
import vplib.model.BodyModel;

public class BodyBoxComponent extends AbstractPhysicsComponent implements IPhysicsComponent {
    public function BodyBoxComponent(uniqueId:String) {
        super(uniqueId);

        _surface = createSurface();
        _model = createModel();
    }

    public function createSurface():Mesh {
        var srf:Mesh = new Box(10, 10, 10);
        srf.setMaterialToAllSurfaces(new FillMaterial(0x999999));
        return srf;
    }

    public function createModel():AbstractPropertyModel {
        return new BodyModel();
    }

    public function createNewInstance():IPhysicsComponent {
        var component:BodyBoxComponent = new BodyBoxComponent("");
        component.setModel(createModel());
        component.setSurface(createSurface());
        return component;
    }

    public function applyModelToSurface():void {
        try {
            _surface.x = Number(_model.getPropertyByName(PropertiesDictionary.get_COORDINATE_X().name).value);
            _surface.y = Number(_model.getPropertyByName(PropertiesDictionary.get_COORDINATE_Y().name).value);
            _surface.z = Number(_model.getPropertyByName(PropertiesDictionary.get_COORDINATE_Z().name).value);
            trace("[AbstractPhysicsComponent] \t- applyModel() - apply coordinate");
        } catch (error:Error) {
            trace(error.message);
        }

        try {
            _surface.scaleX = Number(_model.getPropertyByName(PropertiesDictionary.get_SCALE_X().name).value);
            _surface.scaleY = Number(_model.getPropertyByName(PropertiesDictionary.get_SCALE_Y().name).value);
            _surface.scaleZ = Number(_model.getPropertyByName(PropertiesDictionary.get_SCALE_Z().name).value);
            trace("[AbstractPhysicsComponent] \t- applyModel() - apply scale");
        } catch (error:Error) {
            trace(error.message);
        }
    }

    public function getComponentName():String {
        return "Body_box";
    }
}
}
